<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="请输入设备名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="deviceNumber">
        <el-input
          v-model="queryParams.deviceNumber"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="人员数量" prop="headcount">-->
<!--        <el-input-->
<!--          v-model="queryParams.headcount"-->
<!--          placeholder="请输入人员数量"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="库容" prop="storageCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.storageCapacity"-->
<!--          placeholder="请输入库容"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="罐组" prop="tankGroup">-->
<!--        <el-input-->
<!--          v-model="queryParams.tankGroup"-->
<!--          placeholder="请输入罐组"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="可燃气体探头数量" prop="probeNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.probeNumber"-->
<!--          placeholder="请输入可燃气体探头数量"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供油模式" prop="oilSupplyMode">-->
<!--        <el-input-->
<!--          v-model="queryParams.oilSupplyMode"-->
<!--          placeholder="请输入供油模式"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="油源" prop="oilSource">-->
<!--        <el-input-->
<!--          v-model="queryParams.oilSource"-->
<!--          placeholder="请输入油源"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="实验室" prop="laboratory">-->
<!--        <el-input-->
<!--          v-model="queryParams.laboratory"-->
<!--          placeholder="请输入实验室"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="消防能力(罐、泵)" prop="fireFightingCapability">-->
<!--        <el-input-->
<!--          v-model="queryParams.fireFightingCapability"-->
<!--          placeholder="请输入消防能力(罐、泵)"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车名称" prop="vehicleName">-->
<!--        <el-input-->
<!--          v-model="queryParams.vehicleName"-->
<!--          placeholder="请输入加油车名称"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车型号" prop="vehicleModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.vehicleModel"-->
<!--          placeholder="请输入加油车型号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车制造厂家" prop="manufacturer">-->
<!--        <el-input-->
<!--          v-model="queryParams.manufacturer"-->
<!--          placeholder="请输入加油车制造厂家"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车底盘型号" prop="chassisSpecification">-->
<!--        <el-input-->
<!--          v-model="queryParams.chassisSpecification"-->
<!--          placeholder="请输入加油车底盘型号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车底盘号" prop="chassisNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.chassisNumber"-->
<!--          placeholder="请输入加油车底盘号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车自编号" prop="vehicleNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.vehicleNo"-->
<!--          placeholder="请输入加油车自编号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车出厂日期" prop="productionDate">-->
<!--        <el-date-picker clearable size="small"-->
<!--          v-model="queryParams.productionDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择加油车出厂日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加油车出厂编号" prop="factoryNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.factoryNumber"-->
<!--          placeholder="请输入加油车出厂编号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-input-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="请输入状态"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用" prop="remarkSpare">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare"-->
<!--          placeholder="请输入备用"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用1" prop="remarkSpare1">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare1"-->
<!--          placeholder="请输入备用1"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用2" prop="remarkSpare2">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare2"-->
<!--          placeholder="请输入备用2"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用3" prop="remarkSpare3">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare3"-->
<!--          placeholder="请输入备用3"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用4" prop="remarkSpare4">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare4"-->
<!--          placeholder="请输入备用4"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用5" prop="remarkSpare5">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarkSpare5"-->
<!--          placeholder="请输入备用5"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="部门ID" prop="deptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.deptId"-->
<!--          placeholder="请输入部门ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['warehouse:infrastructure:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['warehouse:infrastructure:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['warehouse:infrastructure:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['warehouse:infrastructure:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infrastructureList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="50" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="主键ID" align="center" prop="id" />-->
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备编号" align="center" prop="deviceNumber" />
      <el-table-column label="人员数量" align="center" prop="headcount" />
      <el-table-column label="库容" align="center" prop="storageCapacity" />
      <el-table-column label="罐组" align="center" prop="tankGroup" />
      <el-table-column label="可燃气体探头数量" align="center" prop="probeNumber" />
      <el-table-column label="供油模式" align="center" prop="oilSupplyMode" />
      <el-table-column label="油源" align="center" prop="oilSource" />
      <el-table-column label="实验室" align="center" prop="laboratory" />
      <el-table-column label="消防能力(罐、泵)" align="center" prop="fireFightingCapability" />
      <el-table-column label="加油车名称" align="center" prop="vehicleName" />
      <el-table-column label="加油车型号" align="center" prop="vehicleModel" />
      <el-table-column label="加油车制造厂家" align="center" prop="manufacturer" />
      <el-table-column label="加油车底盘型号" align="center" prop="chassisSpecification" />
      <el-table-column label="加油车底盘号" align="center" prop="chassisNumber" />
      <el-table-column label="加油车自编号" align="center" prop="vehicleNo" />
      <el-table-column label="加油车出厂日期" align="center" prop="productionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加油车出厂编号" align="center" prop="factoryNumber" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="备注" align="center" prop="remark" />
<!--      <el-table-column label="备用" align="center" prop="remarkSpare" :formatter="remarkSpareFormat" />-->
<!--      <el-table-column label="备用1" align="center" prop="remarkSpare1" :formatter="remarkSpare1Format" />-->
<!--      <el-table-column label="备用2" align="center" prop="remarkSpare2" :formatter="remarkSpare2Format" />-->
<!--      <el-table-column label="备用3" align="center" prop="remarkSpare3" :formatter="remarkSpare3Format" />-->
<!--      <el-table-column label="备用4" align="center" prop="remarkSpare4" :formatter="remarkSpare4Format" />-->
<!--      <el-table-column label="备用5" align="center" prop="remarkSpare5" :formatter="remarkSpare5Format" />-->
<!--      <el-table-column label="部门ID" align="center" prop="deptId" :formatter="deptIdFormat" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['warehouse:infrastructure:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['warehouse:infrastructure:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改单位基础设施设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="设备名称" prop="deviceName">
          <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="设备编号" prop="deviceNumber">
          <el-input v-model="form.deviceNumber" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="人员数量" prop="headcount">
          <el-input-number v-model="form.headcount" placeholder="请输入人员数量" />
        </el-form-item>
        <el-form-item label="库容" prop="storageCapacity">
          <el-input-number v-model="form.storageCapacity" placeholder="请输入库容" />
        </el-form-item>
        <el-form-item label="罐组" prop="tankGroup">
          <el-input v-model="form.tankGroup" placeholder="请输入罐组" />
        </el-form-item>
        <el-form-item label="可燃气体探头数量" prop="probeNumber">
          <el-input-number v-model="form.probeNumber" placeholder="请输入可燃气体探头数量" />
        </el-form-item>
        <el-form-item label="供油模式" prop="oilSupplyMode">
          <el-input v-model="form.oilSupplyMode" placeholder="请输入供油模式" />
        </el-form-item>
        <el-form-item label="油源" prop="oilSource">
          <el-input v-model="form.oilSource" placeholder="请输入油源" />
        </el-form-item>
        <el-form-item label="实验室" prop="laboratory">
          <el-input v-model="form.laboratory" placeholder="请输入实验室" />
        </el-form-item>
        <el-form-item label="消防能力(罐、泵)" prop="fireFightingCapability">
          <el-input v-model="form.fireFightingCapability" placeholder="请输入消防能力(罐、泵)" />
        </el-form-item>
        <el-form-item label="加油车名称" prop="vehicleName">
          <el-input v-model="form.vehicleName" placeholder="请输入加油车名称" />
        </el-form-item>
        <el-form-item label="加油车型号" prop="vehicleModel">
          <el-input v-model="form.vehicleModel" placeholder="请输入加油车型号" />
        </el-form-item>
        <el-form-item label="加油车制造厂家" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入加油车制造厂家" />
        </el-form-item>
        <el-form-item label="加油车底盘型号" prop="chassisSpecification">
          <el-input v-model="form.chassisSpecification" placeholder="请输入加油车底盘型号" />
        </el-form-item>
        <el-form-item label="加油车底盘号" prop="chassisNumber">
          <el-input v-model="form.chassisNumber" placeholder="请输入加油车底盘号" />
        </el-form-item>
        <el-form-item label="加油车自编号" prop="vehicleNo">
          <el-input v-model="form.vehicleNo" placeholder="请输入加油车自编号" />
        </el-form-item>
        <el-form-item label="加油车出厂日期" prop="productionDate">
          <el-date-picker clearable size="small"
            v-model="form.productionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择加油车出厂日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="加油车出厂编号" prop="factoryNumber">
          <el-input v-model="form.factoryNumber" placeholder="请输入加油车出厂编号" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-input v-model="form.status" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
<!--        <el-form-item label="备用" prop="remarkSpare">-->
<!--          <el-input v-model="form.remarkSpare" placeholder="请输入备用" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用1" prop="remarkSpare1">-->
<!--          <el-input v-model="form.remarkSpare1" placeholder="请输入备用1" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用2" prop="remarkSpare2">-->
<!--          <el-input v-model="form.remarkSpare2" placeholder="请输入备用2" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用3" prop="remarkSpare3">-->
<!--          <el-input v-model="form.remarkSpare3" placeholder="请输入备用3" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用4" prop="remarkSpare4">-->
<!--          <el-input v-model="form.remarkSpare4" placeholder="请输入备用4" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用5" prop="remarkSpare5">-->
<!--          <el-input v-model="form.remarkSpare5" placeholder="请输入备用5" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="部门ID" prop="deptId">-->
<!--          <el-input v-model="form.deptId" placeholder="请输入部门ID" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfrastructure, getInfrastructure, delInfrastructure, addInfrastructure, updateInfrastructure, exportInfrastructure } from "@/api/warehouse/infrastructure";

export default {
  name: "Infrastructure",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单位基础设施设备表格数据
      infrastructureList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceName: null,
        deviceNumber: null,
        headcount: null,
        storageCapacity: null,
        tankGroup: null,
        probeNumber: null,
        oilSupplyMode: null,
        oilSource: null,
        laboratory: null,
        fireFightingCapability: null,
        vehicleName: null,
        vehicleModel: null,
        manufacturer: null,
        chassisSpecification: null,
        chassisNumber: null,
        vehicleNo: null,
        productionDate: null,
        factoryNumber: null,
        status: null,
        remarkSpare: null,
        remarkSpare1: null,
        remarkSpare2: null,
        remarkSpare3: null,
        remarkSpare4: null,
        remarkSpare5: null,
        deptId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询单位基础设施设备列表 */
    getList() {
      this.loading = true;
      listInfrastructure(this.queryParams).then(response => {
        this.infrastructureList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deviceName: null,
        deviceNumber: null,
        headcount: null,
        storageCapacity: null,
        tankGroup: null,
        probeNumber: null,
        oilSupplyMode: null,
        oilSource: null,
        laboratory: null,
        fireFightingCapability: null,
        vehicleName: null,
        vehicleModel: null,
        manufacturer: null,
        chassisSpecification: null,
        chassisNumber: null,
        vehicleNo: null,
        productionDate: null,
        factoryNumber: null,
        status: null,
        remark: null,
        remarkSpare: null,
        remarkSpare1: null,
        remarkSpare2: null,
        remarkSpare3: null,
        remarkSpare4: null,
        remarkSpare5: null,
        createBy: null,
        createTime: null,
        deptId: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加单位基础设施设备";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfrastructure(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改单位基础设施设备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfrastructure(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfrastructure(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除单位基础设施设备编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfrastructure(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有单位基础设施设备数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInfrastructure(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
